package com.yfqy.app.modules.shoppingcart.resource;

import com.yfqy.app.domain.vo.ResultVO;
import com.yfqy.app.modules.shoppingcart.dto.AddToCartDTO;
import com.yfqy.app.modules.shoppingcart.dto.CartOperateDTO;
import com.yfqy.app.modules.shoppingcart.service.ShoppingCartService;
import com.yfqy.app.modules.shoppingcart.vo.CartListVO;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/client/shopping-cart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车
     *
     * @param dto
     * @return
     */
    @PostMapping("/addToCart")
    public ResultVO<String> addShoppingCart(@Valid @RequestBody AddToCartDTO dto) {
        return ResultVO.data(shoppingCartService.addToCart(dto));
    }

    /**
     * 购物车页面点击+
     *
     * @param dto
     * @return
     */
    @PostMapping("/increase")
    public ResultVO<Void> increase(@RequestBody @Valid CartOperateDTO dto) {
        shoppingCartService.increase(dto);
        return ResultVO.success();
    }

    /**
     * 购物车页面点击-
     *
     * @param dto
     * @return
     */
    @PostMapping("/decrease")
    public ResultVO<Void> decrease(@RequestBody @Valid CartOperateDTO dto) {
        shoppingCartService.decrease(dto);
        return ResultVO.success();
    }

    /**
     * 购物车商品列表
     *
     * @return
     */
    @GetMapping("/getCartList")
    public ResultVO<CartListVO> getCartList() {
        return ResultVO.data(shoppingCartService.getCartList());
    }


    /**
     * 取消
     *
     * @return
     */
    @PostMapping("/cancel")
    public ResultVO<Void> cancel(@RequestBody @Valid CartOperateDTO dto) {
        shoppingCartService.cancel(dto);
        return ResultVO.success();
    }

    /**
     * 选中
     *
     * @return
     */
    @PostMapping("/choose")
    public ResultVO<Void> choose(@RequestBody @Valid CartOperateDTO dto) {
        shoppingCartService.choose(dto);
        return ResultVO.success();
    }

    /**
     * 全选/取消全选购物车商品
     *
     * @return
     */
    @PostMapping("/toggleAll")
    public ResultVO<Void> toggleAll() {
        shoppingCartService.toggleAll();
        return ResultVO.success();
    }


}
